<?php
require_once 'inc.php';

for ($i=500001; $i<880000; $i++)
{
	update_download_stats($i);
}


function update_download_stats($i)
{
	$page_file = sprintf("%s%s/%s.html", PAGE_BASE_HASH_DIR, floor($i/10000), $i);
	$image_file = sprintf("%s%s/%s.jpg", IMAGE_BASE_HASH_DIR, floor($i/10000), $i);

	
	
	$page_size = file_exists($page_file) ? filesize($page_file) : 0;
	$image_size = file_exists($image_file) ? filesize($image_file) : 0;
	
	sys::sql("insert into wallbase_download_stats (image_index, page_size, image_size)"
		."values (%d, %d, %d) on duplicate key update page_size='%d', image_size='%d';",
		$i, $page_size, $image_size, $page_size, $image_size);
}
/*
for ($sub_dir=0; $sub_dir<50; $sub_dir++)
{
	echo $sub_dir."\n";
	$dir = PAGE_BASE_HASH_DIR.$sub_dir;
	$stats = dir_stat($dir);
	
	$s = "";
	foreach ($stats as $file => $size)
	{
		if ($size == 0) continue;
		
		$s .= $file."\t".$size."\n";
	}
	file_put_contents("page.stat.txt", $s, FILE_APPEND);
	break;
}

function dir_stat($dir)
{
	$retarr = array();
	if ($handle = opendir($dir)) {
		while (false !== ($filename = readdir($handle))) {
			if ($filename == "." || $filename == "..")
				continue;
			$file = $dir.'/'.$filename;
			$retarr[$file] = filesize($file);
		}
		closedir($handle);
	}
	
	
	return $retarr;
}
*/